package com.sky.financelake.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.recyclerview.widget.RecyclerView;

import com.sky.financelake.R;
import com.sky.financelake.bean.dto.SimpleStockDto;

import java.util.List;

public class SimplePlateAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    public static final String TAG = SimplePlateAdapter.class.getCanonicalName();

    private final List<SimpleStockDto> stockDtos;
    private final Context mContext;

    public SimplePlateAdapter(List<SimpleStockDto> stockDtos, Context mContext) {
        this.stockDtos = stockDtos;
        this.mContext = mContext;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_plate_stock, parent, false);
        return new StockViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof StockViewHolder) {
            ((StockViewHolder) holder).name.setText(stockDtos.get(position).getName());
            ((StockViewHolder) holder).code.setText(stockDtos.get(position).getCode());
        }
    }

    @Override
    public int getItemCount() {
        return stockDtos.size();
    }

    public interface OnItemClickListener {
        void onClick(int position);
    }

    public OnItemClickListener listener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.listener = onItemClickListener;
    }

    public class StockViewHolder extends RecyclerView.ViewHolder {

        AppCompatTextView name, code;

        public StockViewHolder(@NonNull View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.tv_stock_name);
            code = itemView.findViewById(R.id.tv_stock_code);

        }
    }
}
